package com.seehope.practice;

import java.util.concurrent.atomic.AtomicInteger;

public class Shangji7 {

	private int j;

	public static void main(String[] args) {
		Shangji7 tt = new Shangji7();
		Inc inc = tt.new Inc();
		Dec dec = tt.new Dec();

		Thread t1 = new Thread(inc);
		Thread t2 = new Thread(dec);
		Thread t3 = new Thread(inc);
		Thread t4 = new Thread(dec);
		t1.start();
		t2.start();
		t3.start();
		t4.start();

	}

	private synchronized void inc() {
		j++;
		System.out.println(Thread.currentThread().getName() + "inc:" + j);
	}

	private synchronized void dec() {
		j--;
		System.out.println(Thread.currentThread().getName() + "dec:" + j);
	}

	class Inc implements Runnable {
		@Override
		public void run() {
			for (int i = 0; i < 10; i++) {
				inc();

			}
		}
	}

	class Dec extends Thread {
		@Override
		public void run() {
			for (int i = 0; i < 10; i++) {
				dec();

			}
		}

	}
}